define(['backbone', 'framework', '_global', '_netPointDialog'],
    function (Backbone, framework, _gl, _netPointDialog) {
        return Backbone.Router.extend({
            events: {
                "click #switchNetPointBtn": "netPointDialog"
            },
            initialize: function () {
                //_initSystem.init();
                framework.initNetPoint();
                framework.initSystemSetting();
                framework.prodCookie().init();
                framework.closeAll();
                this.netPointDialog();
            },
            netPointDialog: function () {
                $("#switchNetPointBtn").off("click").on("click", function () {
                    _netPointDialog.init();
                });

                /* $("#switchNetPointBtn").off("click").on("click", function () {
                     var href = $(this).attr("href");
                     if (!!_CD.getTotal()) {
                         var  layerIndex = _gl.confirm({
                             title: '温馨提示',
                             content: '切换网点购物车内商品将被清空？',
                             btnName: ['继续切换', '取消切换'],
                             yes: function () {
                                 _gl.close(layerIndex);
                                 return false;
                             },
                             no: function () {
                                 _CD.clear();
                                 window.location.href = (window.location.href.indexOf("#") > 0 ? window.location.href.split("#")[0] : window.location.href) + href;
                             }
                         });
                         return false;
                     }
                 });*/
            },
            routes: {
                "": "goods",
                "goods": "goods",
                "goods/:navCode": "goods",   // --- gai d ong
                "goods/:navCode/:fromWhere": "goods",   // --- gai d ong
                "goods/:navCode/:fromWhere/:key": "goods",   // --- gai d ong
                "cart/:navCode": "cart",
                "detail/:categoryid/:pno": "detail",
                "order": "order",
                "paymentOrder": "paymentOrder",
                //"netPoint/:districtid": "netPoint",
                "sweepPay": "sweepPay",
                "helpBuy": "helpBuy"
            },
            goods: function (navCode, fromWhere,key) {
                var self = this;
                if (!!fromWhere && (fromWhere != 'search')) {
                    framework.closeAll();
                    self.hideDetail();
                    framework.restartAD();
                } else {
                    require(['app/view/viewGoods'], function (viewGoods) {
                        framework.closeAll();
                        if (!self.viewGoods) {
                            self.viewGoods = new viewGoods();
                        }
                        self.viewGoods.render(navCode,key);
                    });
                }
            },
            cart: function (navCode) {
                var self = this;
                require(['app/view/viewCart'], function (viewCart) {
                    framework.closeAll();
                    if (!self.viewCart) {
                        self.viewCart = new viewCart();
                    }
                    self.viewCart.render(navCode);
                });
            },
            detail: function (categoryid, pno) {
                var self = this;
                self.showDetail();
                require(['app/view/viewDetail'], function (viewDetail) {
                    framework.closeAll();
                    if (!self.viewDetail) {
                        self.viewDetail = new viewDetail();
                    }
                    self.viewDetail.render(categoryid, pno);
                });
            },
            order: function () {
                var self = this;
                require(['app/view/viewOrder'], function (viewOrder) {
                    framework.closeAll();
                    if (!self.viewOrder) {
                        self.viewOrder = new viewOrder();
                    }
                    self.viewOrder.render();
                });
            },
            sweepPay: function () {
                var self = this;
                require(['app/view/viewSweepPay'], function (viewSweepPay) {
                    framework.closeAll();
                    if (!self.viewSweepPay) {
                        self.viewSweepPay = new viewSweepPay();
                    }
                    self.viewSweepPay.render();
                });
            },
            helpBuy: function () {
                var self = this;
                require(['app/view/viewHelpBuy'], function (viewHelpBuy) {
                    framework.closeAll();
                    if (!self.viewHelpBuy) {
                        self.viewHelpBuy = new viewHelpBuy();
                    }
                    self.viewHelpBuy.render();
                });
            },
            netPoint: function (districtid) {
                /* _gl.closeAll();
                 if (!this.viewNetPoint) {
                     this.viewNetPoint = new viewNetPoint(); 
                 }
                 this.viewNetPoint.render({ districtid: districtid });*/
            },
            hideDetail: function () {
                $("#floor1").show();
                $("#floor2").hide();
            },
            showDetail: function () {
                $("#floor1").hide();
                $("#floor2").show();
            }
        });
    })